layui.use(['jquery','layer','table','form'],function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var table = layui.table;
    var form = layui.form;

    /*表格渲染*/
    var account="";
    var nickname="";
    var seeUser = table.render({
        elem:"#table",
        url:"/coupon/getAllUserCoupon?account=" +account+"&nickname="+nickname,
        toolbar:"#tool",
        defaultToolbar: ['','',''],
        page:true,
        limit:10,
        limits:[10,15,20,25],
        cols:[
            [
                {type:"checkbox",aling:"center"},
                {type:"numbers",title:"序号",aling:"center"},
                {field:"account",title:"用户账号",aling:"center"},
                {field:"nickname",title:"用户昵称",aling:"center"},
                {field:"used",title:"已使用",aling:"center"},
                {field:"noUsed",title:"未使用",aling:"center"},
                {field:"countEnd",title:"已过期",aling:"center"},
                {title:"操作",aling:"center",templet:function (data) {
                        return "<a href='javascript:giveCoupons("+data.userId+");' style='color: #2F4056;margin-left: 95px'>赠送优惠券</a>"
                    }},
            ]
        ]
    });

    /*模糊查询*/
    form.on("submit(sub)",function () {
        var account = $("#account").val();
        var nickname = $("#userName").val();
        seeUser.reload({
            url:"/coupon/getAllUserCoupon?account=" +account+"&nickname="+nickname
        });
        return false;
    });

    /*重置开始*/
    form.on("submit(subs)",function () {
        seeUser.reload({
            url:"/coupon/getAllUserCoupon?account=" +account+"&nickname="+nickname
        });
    })

    /*赠送优惠券*/
    giveCoupons = function giveCoupons(userId){
        layer.open({
            type:2,
            shode:0,
            maxmin:true,
            title:"赠送优惠券",
            content:"/newcoupon/coupon-give.html",
            area:["1240px","620px"],
            success:function (layero,index) {
                var obj = layero.find('iframe').contents();
                obj.find("input[name=userId]").val(userId);
            }
        })
    }

    /*刷新*/
    Refresh = function Refresh() {
        location.reload();
    };

    /*返回*/
    goBack = function goBack() {
        parent.$('#Jump').val('首页');
        parent.getQuick();
        return;
    }

});